package com.bm.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bm.entity.GcAl;
import com.bm.entity.News;
import com.bm.entity.PageBean;
import com.bm.service.GcAlService;
import com.bm.service.NewsService;
import com.bm.service.impl.GcAlServiceImpl;
import com.bm.service.impl.NewsServiceImpl;

/**
 * Servlet implementation class InsertGcalServlet
 */
@WebServlet("/InsertGcalServlet")
public class InsertGcalServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InsertGcalServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		GcAlService gs = new GcAlServiceImpl();
		String pd = request.getParameter("gc");
		String pd1 = request.getParameter("type");
		
		if(pd1.equals("delete")) {
			GcAl gcal = new GcAl();
			int id = Integer.parseInt(request.getParameter("id")); 
			gcal.setProjectId(id);;
			boolean bl = gs.sdeleteXw(gcal);
			if(bl == true) {
				PageBean<GcAl> gcList = new PageBean<GcAl>();
				gcList = gs.pagesList(gcList);
				request.setAttribute("gcList",gcList);
				request.getRequestDispatcher("selectGc.jsp").forward(request, response);
			}else {
				
				request.getRequestDispatcher("selectGc.jsp").forward(request, response);
			}
		}
		
		if(pd.equals("gc")) {
			GcAl gcal = new GcAl();
			
			String urls = request.getParameter("urls");
			String types = request.getParameter("types");
			
			if(urls.equals("")) {
				String gl = "失败 请添加路径";
				request.setAttribute("gl", gl);
				request.getRequestDispatcher("insert.jsp").forward(request, response);
			}
			if(types.equals("")) {
				String gl = "失败 请添加名字";
				request.setAttribute("gl", gl);
				request.getRequestDispatcher("insert.jsp").forward(request, response);
			}
			gcal.setProjectImage(urls);
			gcal.setProjectName(types);
			boolean tf = gs.sinsertGc(gcal);
			if(tf==true) {
				String gl = "添加成功请在工程案例查看";
				request.setAttribute("gl", gl);
				request.getRequestDispatcher("insert.jsp").forward(request, response);
			}else {
				String gl = "添加失败";
				request.setAttribute("gl", gl);
				request.getRequestDispatcher("insert.jsp").forward(request, response);
			}
		}
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
